﻿/*  
	------------------------------------------------------------------------
	 NQ Core Library
	
	 Homepage: http://www.awzhome.de/
	------------------------------------------------------------------------
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Core Library.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	------------------------------------------------------------------------
*/

using System;

namespace AWZhome.NQ.Core.Fluent
{
	/// <summary>
	/// Wraps a "lazy created" list of service instances to be used
	/// with the NQ fluent interface, that allows to create dependent services.
	/// </summary>
	/// <typeparam name="T">Type of the service instances.</typeparam>
	public class LazyCreatedDepServiceListWrapper<T> : LazyCreatedServiceListWrapper<T>
	{

		internal LazyCreatedDepServiceListWrapper(string listName)
			: base(listName)
		{
		}

		/// <summary>
		/// Passes a parent service to the created instances.
		/// </summary>
		/// <typeparam name="P">Type of the parent service.</typeparam>
		/// <param name="parent">Instance of the parent service, that is passed to created service instance.</param>
		/// <returns>A <see cref="AWzhome.NQ.Core.Fluent.ServiceListWrapper{T}">ServiceListWrapper&lt;T&gt;</see>
		/// object to perform other operations on the service list.</returns>
		public ServiceListWrapper<T> DependentOn<P>(P parent)
		{
			_serviceInstances =
					NQServiceManager.Instance.CreateAttachedDepServices<T, P>(
						_listName, parent
					);
			return this;
		}

		/// <summary>
		/// Passes two parent services to the created instances.
		/// </summary>
		/// <typeparam name="P1">Type of the first parent service.</typeparam>
		/// <typeparam name="P2">Type of the second parent service.</typeparam>
		/// <param name="parent1">Instance of the first parent service, that is passed to created service instance.</param>
		/// <param name="parent2">Instance of the second parent service, that is passed to created service instance.</param>
		/// <returns>A <see cref="AWzhome.NQ.Core.Fluent.ServiceListWrapper#T">ServiceListWrapper&lt;T&gt;</see>
		/// object to perform other operations on the service list.</returns>
		public ServiceListWrapper<T> DependentOn<P1, P2>(P1 parent1, P2 parent2)
		{
			_serviceInstances =
					NQServiceManager.Instance.CreateAttachedDepServices2<T, P1, P2>(
						_listName, parent1, parent2
					);
			return this;
		}

		/// <summary>
		/// Excludes single-instance services into service instance creation
		/// from the AttachList. This is the default behavior.
		/// </summary>
		public LazyCreatedDepServiceListWrapper<T> WithoutSingleInstanceServices
		{
			get
			{
				_includeSingleInstanceServices = false;
				return this;
			}
		}

		/// <summary>
		/// Includes multi-instance services into service instance creation
		/// from the AttachList. This is the default behavior.
		/// </summary>
		public LazyCreatedDepServiceListWrapper<T> WithMultiInstanceServices
		{
			get
			{
				_includeMultiInstanceServices = true;
				return this;
			}
		}

	}
}

